from google.appengine.ext import db
from datetime import timedelta

class Competition(db.Model):
  name = db.StringProperty()
  date = db.DateProperty()
  organizer = db.StringProperty()
  password = db.StringProperty()
  country = db.StringProperty()
  uname = db.StringProperty()
  uemail = db.StringProperty()

class Class(db.Model):
  name = db.StringProperty(required=True)
  ident = db.StringProperty()
  competitionid = db.ReferenceProperty(Competition)
  ControlNames = db.StringListProperty()
  ControlCodes = db.ListProperty(int)

class Runner(db.Model):
  id = db.IntegerProperty()
  firstname = db.StringProperty()
  lastname = db.StringProperty()
  clubname = db.StringProperty()
  runnerClass = db.ReferenceProperty(Class)
  totaltime = db.IntegerProperty()
  status = db.IntegerProperty()
  SplitControls = db.ListProperty(int)
  SplitTimes = db.ListProperty(int)
  changetime = db.DateTimeProperty()


class TimeFunctions:
	def formatTime(self,time,status):
		if status == 0:
	   		td = timedelta(milliseconds = time*10)
			return str(td)
		else:
			if status == 1:
				return "MP"
			elif status == 2:
				return "DSQ"
			elif status == 3:
				return "OT"
			elif status == 4:
				return "DNS"
			elif status == 5:
				return "WO"
			elif status == 6:
				return "MOVEDUP"		    
		return '';
